<?php 

/**
 * 控制基类
 */

class Controller extends Smarty
{
	public function __construct()
	{
		// Smarty配置文件 配置
		$this->setTemplateDir('./views')
			   ->setCompileDir('./runtime/views_c')
			   ->setConfigDir('./configs')
			   ->setCacheDir('./runtime/caches');
		// 配置 模板定界符 在这不合适，若以后想改，但是我们不允许到基类中改动，故放在configs中
		$this->left_delimiter = LEFT_D;
		$this->right_delimiter = RIGHT_D;
		// 缓存 配置
		$this->caching = CACHING;
		// 缓存时间 配置
		$this->cache_lifetime = CACHE_LIFETIME;
	}

	// 跳转
	public function redirect($message, $url=null)
	{
		echo "<script>alert('{$message}')</script>";
		if (empty($url)) {
			echo "<script>history.back()</script>";
		} else {
			echo "<script>location.href='{$url}'</script>";
		}
		
	}

	// 处理调用不存在的方法
	public function __call($fun, $params)
	{
		header('HTTP/1.o 404 not found');//非IE
		header('Status:404 not found');//兼容IE
		echo "<h1>404 NOT FOUND</h1>";
		exit;
	}
}

